//
//  ZPBFistPageCollectionViewCell.m
//  WZLProduct
//
//  Created by boys on 16/3/18.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "ZPBFistPageCollectionViewCell.h"
#import "ZPBHeartCollectionReusableView.h"
#import "ZPBSecondCollectionViewCell.h"
#import "ZPBHeartOneCollectionReusableView.h"
#import "ZPBOneCollectionViewCell.h"
#import "ZPBTwoCollectionViewCell.h"
#import "ZPBThreeCollectionViewCell.h"

@interface ZPBFistPageCollectionViewCell ()<UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView; ///collectionView上的collectionView
@property (nonatomic, strong) NSMutableArray *dataSouce; ///数据源

/**
 下49 导航64
 */
@end

@implementation ZPBFistPageCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollectionView];
    }
    return self;
}

#pragma mark - 创建collectionView
- (void)createCollectionView {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.itemSize = CGSizeMake(0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 35, kScreenWidth, kScreenHeight - 149) collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    
    [self.contentView addSubview:_collectionView];
    
    //注册头
    [_collectionView registerClass:[ZPBHeartCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    [_collectionView registerClass:[ZPBHeartOneCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ZPBHeartOneCollectionReusableView"];
    
    [_collectionView registerClass:[ZPBSecondCollectionViewCell class ]forCellWithReuseIdentifier:@"ZPBSecondCollectionViewCell"];
    [_collectionView registerClass:[ZPBOneCollectionViewCell class] forCellWithReuseIdentifier:@"ZPBOneCollectionViewCell"];
    [_collectionView registerClass:[ZPBTwoCollectionViewCell class] forCellWithReuseIdentifier:@"ZPBTwoCollectionViewCell"];
    [_collectionView registerClass:[ZPBSecondCollectionViewCell class] forCellWithReuseIdentifier:@"ZPBSecondCollectionViewCell"];
    [_collectionView registerClass:[ZPBThreeCollectionViewCell class] forCellWithReuseIdentifier:@"ZPBThreeCollectionViewCell"];
}


//给头视图赋值
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader) {
        if (indexPath.section == 0) {
            
            ZPBHeartCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
            return header;
            
        }else{
            ZPBHeartOneCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"ZPBHeartOneCollectionReusableView" forIndexPath:indexPath];
            
            return header;
        }
    }
    return nil;
    
}

//头视图的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        
        return CGSizeMake(kScreenWidth, kScreenHeight / 4);
    }
   return CGSizeMake(kScreenWidth, 40);
}

//每个分区的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return CGSizeMake([UIScreen mainScreen].bounds.size.width / 5, 90);
    }else if(indexPath.section == 1 ){
        return CGSizeMake([UIScreen mainScreen].bounds.size.width , 70);
    }else if (indexPath.section == 2 || indexPath.section == 3 || indexPath.section == 5|| indexPath.section == 6 ){
        return CGSizeMake(kScreenWidth / 3 - 20, 150);
       
    }else if (indexPath.section == 4 || indexPath.section == 7 || indexPath.section == 8) {
        return CGSizeMake([UIScreen mainScreen].bounds.size.width, 70);
    }
    return CGSizeMake(0, 0);
}
//cell个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 4;
    }if (section == 1) {
        return 3;
    }if (section == 2) {
        return 6;
    }if (section == 3) {
        return 3;
    }if (section == 4) {
        return 3;
    }if (section == 5) {
        return 3;
    }if (section == 6) {
        return 3;
    }if (section == 7) {
        return 3;
    }if (section == 8) {
      return 1;
    }
    return 1;
}
//section的数量
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 9;
}
//设置 layout大小
- (UIEdgeInsets )collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 15, 0, 15);
}
//cell赋值
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        ZPBSecondCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBSecondCollectionViewCell" forIndexPath:indexPath];
        
        return cell;
    }else if(indexPath.section == 1) {
        ZPBOneCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBOneCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor blueColor];
        return cell;
    }else if(indexPath.section == 2){
        ZPBTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBTwoCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor magentaColor];
        return cell;
    }else if(indexPath.section == 3) {
        ZPBTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBTwoCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor magentaColor];
        return cell;
    }else if(indexPath.section == 4) {
        ZPBThreeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBThreeCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor magentaColor];
        return cell;

    }else if(indexPath.section ==5) {
        ZPBTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBTwoCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor orangeColor];
        return cell;

    }else if(indexPath.section == 6) {
        ZPBTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBTwoCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor magentaColor];
        return cell;

    }else if(indexPath.section == 7){
        ZPBThreeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBThreeCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor magentaColor];
        return cell;

    }else if(indexPath.section == 8){
        ZPBThreeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZPBThreeCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor magentaColor];
        return cell;

    }
    
    return nil;
}


@end
